<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="e" uri="/easytogo-tags"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>注册</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<e:base/>
	<script type="text/javascript">
	 	var flag={"username":false,"password":false,"email":false,"icode":false};
		function usernameVerify(username){
			if(username==undefined||username==""||username==null){
				$("#msg1").attr("color","red").text("用户名不能为空");
				flag.username=false;
				return;
			}
			var url="${pageContext.request.contextPath}/appuser/appuser_usernameExist.action";
			$.ajax({
				type: "post",
				url: url,
				data: {"username":username},
				dataType:"html",
				success: function(msg){
					  if(msg=="success"){
						  $("#msg1").attr("color","green").text("用户名可用");
						  flag.username=true;
					  }else{
						  $("#msg1").attr("color","red").text(msg);
						  flag.username=false;
					  }
				}
			}); 
		}
		function password1Verify(password){
			if(password==undefined||password==""||password==null){
				$("#msg4").attr("color","red").text("密码不能为空");
				flag.password=false;
			}else{
				$("#msg4").attr("color","green").text("木有问题");
				flag.password=true;
			}
		}
		function password2Verify(password){
			if(password==undefined||password==""||password==null){
				$("#msg5").attr("color","red").text("密码不能为空");
				flag.password=false;
				return;
			}
			if($("#password1").val()!=$("#password2").val()){
				$("#msg5").attr("color","red").text("两次密码不一致");
				flag.password=false;
				return;
			}
			$("#msg5").attr("color","green").text("木有问题");
			flag.password=true;
		}
		function emailVerify(email){
			if(email==undefined||email==""||email==null){
				$("#msg2").attr("color","red").text("邮箱不能为空");
				flag.email=false;
				return;
			}
			if(!/^[a-zA-Z0-9_]+@([a-zA-Z0-9_]+.)+[a-zA-Z]+$/.test(email)){
				$("#msg2").attr("color","red").text("邮箱格式错误");
				flag.email=false;
				return;
			}
			var url="${pageContext.request.contextPath}/appuser/appuser_emailExist.action";
			$.ajax({
				type: "post",
				url: url,
				data: {"email":email},
				dataType:"html",
				success: function(msg){
					  if(msg=="success"){
						  $("#msg2").attr("color","green").text("邮箱可用");
						  flag.email=true;
					  }else{
						  $("#msg2").attr("color","red").text(msg);
						  flag.email=false;
					  }
				}
			}); 
		}
		function icodeVerify(icode){
			if(icode==undefined||icode==""||icode==null){
				$("#msg3").attr("color","red").text("验证码不能为空");
				flag.icode=false;
				return;
			}
			var url="${pageContext.request.contextPath}/appuser/appuser_icodeVerify.action";
			$.ajax({
				type: "post",
				url: url,
				data: {"icode":icode},
				dataType:"html",
				success: function(msg){
					  if(msg=="success"){
						  $("#msg3").attr("color","green").text("木有问题");
						  flag.icode=true;
					  }else{
						  $("#msg3").attr("color","red").text(msg);
						  flag.icode=false;
					  }
				}
			}); 
		}
		function submitVerify(obj){
			$("input[type!=button]").each(function(){
				this.onblur();
			});
			if(flag.username&&flag.password&&flag.email&&flag.icode){
				obj.disabled=true;
				document.registForm.submit();
			}
		}
	</script>
  </head>
  
  <body>
  	<form name="registForm" action="${pageContext.request.contextPath }/appuser/appuser_regist.action" method="post">
	   <table border="1">
	    	<tr>
	    		<td>用户名</td><td><input name="username" type="text" value="${username }" onblur="usernameVerify(this.value);"/></td><td><font color="red" id="msg1">${msg1 }</font>&nbsp;</td>
	    	</tr>
	    	<tr>
	    		<td>密码</td><td><input id="password1" name="password" type="password" onblur="password1Verify(this.value);"/></td><td><font color="red" id="msg4"></font>&nbsp;</td>
	    	</tr>
	    	<tr>
	    		<td>确认密码</td><td><input id="password2" type="password" onblur="password2Verify(this.value);"/></td><td><font color="red" id="msg5"></font>&nbsp;</td>
	    	</tr>
	    	<tr>
	    		<td>Email</td><td><input name="email" type="text" value="${email }" onblur="emailVerify(this.value);"/></td><td><font color="red" id="msg2">${msg2 }</font>&nbsp;</td>
	    	</tr>
	    	<tr>
	    		<td>姓名</td><td><input name="realname" type="text" value="${realname }" onblur=""/></td><td>&nbsp;</td>
	    	</tr>
	    	<tr>
	    		<td>验证码</td><td valign="bottom"><input name="icode" type="text" size="5" onblur="icodeVerify(this.value);"/><a href="javascript:" onclick="document.getElementById('validateImage').src='${pageContext.request.contextPath }/common/iCode.action?time='+parseInt(Math.random()*(999999-0+1)+0); "><img alt="看不清楚,点击更换" id="validateImage" src="${pageContext.request.contextPath }/common/iCode.action" width="80" height="24" onclick="this.src='../user/imageCode.action?time='+parseInt(Math.random()*(999999-0+1)+0); " border="0"/></a></td><td><font color="red" id="msg3">${msg3 }</font>&nbsp;</td>
	    	</tr>
	    	<tr>
	    		<td colspan="3" align="center"><input id="subBtn" type="button" value="注册" onclick="submitVerify(this);"/></td>
	    	</tr>
	    </table>
	  </form>
  </body>
</html>
